package com.lin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lin.base.Result;
import com.lin.entity.GasInfo;
import com.lin.entity.User;
import com.lin.service.GasInfoService;
import com.lin.service.impl.UserServiceImpl;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lin
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/api")
public class    UserController {
    @Resource
    UserServiceImpl userService;

    @Resource
    private GasInfoService gasInfoService;

    @PostMapping("/base/register")
    public Result register(@RequestBody User user) {
        //内部接口
        return Result.ok(userService.saveUser(user));
    }

    @RequestMapping("/base/gaslist")
    public Result getGasListApi() {
        List<GasInfo> gasInfos = gasInfoService.list(new QueryWrapper<GasInfo>().eq("type_id", 1));
        ArrayList<Object> list = new ArrayList<>();
        gasInfos.forEach(gasInfo -> {
           Map map=new HashMap();
           map.put("gasId",gasInfo.getId());
           map.put("name",gasInfo.getData());
           list.add(map);
        });
        return Result.ok(list);
    }
}
